package cn.shutdown.farm.action;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.SessionAttributes;

import sy.action.BaseAction;
import cn.shutdown.farm.model.Land;
import cn.shutdown.farm.service.LandService;

import com.opensymphony.xwork2.Action;

@SessionAttributes
public class UserAction extends BaseAction implements Action, SessionAware {

	private Map<String, Object> session;
	private List<Land> userLands;
	@Autowired
	private LandService landService;

	public String login() {
		session.put("userId", "user1");
		return "loginSuccess";
	}

	public String listLand() {
		String userId = (String) session.get("userId");
		if(StringUtils.isBlank(userId)){
			return "notLogin";
		}
		userLands = landService.findByUserId(userId);
		return "listLand";
	}

	@Override
	public String execute() throws Exception {
		return null;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public List<Land> getUserLands() {
		return userLands;
	}

	public void setUserLands(List<Land> userLands) {
		this.userLands = userLands;
	}

}
